//package com.service.single.config;
//
//import com.alibaba.fastjson.JSON;
//import com.service.single.util.R;
//import com.service.single.util.TokenUtil;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.stereotype.Component;
//import org.springframework.web.servlet.HandlerInterceptor;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
///**
// * @author admin
// * JWT 校验
// */
//@Component
//@Slf4j
//public class TokenInterceptor implements HandlerInterceptor {
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        String requestMethod = "OPTIONS";
//        if (StringUtils.equals(requestMethod, request.getMethod())) {
//            response.setStatus(HttpServletResponse.SC_OK);
//            return true;
//        }
//        // 获取token 并校验
//        String Authorization = request.getHeader("Authorization");
//        String token = Authorization.replace("Bearer ", "");
//        if (StringUtils.isNotBlank(token)) {
//            if (TokenUtil.verify(token)) {
//                return true;
//            }
//        }
//        response.setCharacterEncoding("UTF-8");
//        response.setContentType("application/json; charset=utf-8");
//        response.setStatus(401);
//        R jsonResult = R.faild("认证失败", 401);
//        response.getWriter().append(JSON.toJSONString(jsonResult));
//        return false;
//    }
//}
